#ifndef _T_GL_SPATIAL_TREE_H_
#define _T_GL_SPATIAL_TREE_H_

#include "../interface/I_SpatialTree.h"
#include "../interface/T_Buffer_GL.h"
#include "../interface/T_DoubleBuffer_GL.h"

typedef int T_idx ;
typedef float4 T_pos;

class C_gl_SpatialTree : public I_SpatialTree
{
protected:
public:
	C_gl_SpatialTree(){}
	~C_gl_SpatialTree(){}

	virtual	bool								SearchSplit(float2 **ppPrimBI,
																					float4	*pWS,
																					T_idx *pPosIdx,
																					int nCount, 
																					int nWeight,
																					S_Interval *pInterval,
																					int & axis, 
																					int & sah_bin, 
																					S_TreeNode & s);

	bool												SearchSplit(float2 **ppPrimBI, 
																					T_idx *pPosIdx,
																					int nCount, 
																					S_Interval *pInterval,
																					int & axis, 
																					int & sah_bin, 
																					S_TreeNode & s);

	virtual	void								Create(int nFlag, 
																		 I_Buffer *pVertex, 
																		 I_Buffer *pIndex,
																		 int nVertex, int nPrimitive, 
																		 int nCount, int nDepth,
																		 I_api_Device * pDevice=NULL);

	virtual	void								Create(int nFlag, 
																		 I_Buffer *pVertex, 
																		 I_Buffer *pIndex,
																		 int nVertex, int nPrimitive, 
																		 int nCount, int nDepth,
																		 I_SpatialTree * pShared);

	virtual	void								PrimitiveAABB();

	virtual void								KdTree_p0();
	virtual void								BVHTree_p0();
	virtual	void								KdTree_Instanced_p0();
	virtual	void								BVHTree_Instanced_p0();
	
	virtual	void								ActorData(int nCount, I_api_Device * pDevice);

	virtual	void								KdTree(I_api_Device * pDevice, int nMaxDepth=20, int nCount=1);
	virtual	void								BVHTree(I_api_Device * pDevice, int nMaxDepth=20, int nCount=1);

	virtual	void								KdTree(I_SpatialTree * pShared, int nMaxDepth=20, int nCount=1);
	virtual	void								BVHTree(I_SpatialTree * pShared, int nMaxDepth=20, int nCount=1);

	virtual void								RenderBVHTree(int maxLevel, 
																						matrix4x4 * pModel, 
																						matrix4x4 * pView,
																						matrix4x4 * pProjection, 
																						I_api_Device * pApiDevice);

	virtual void								RenderBVHTreeRayTrace(float3 orig, 
																										float3 dir, 
																										int maxLevel, 
																										bool empty);
};

#endif